package config

import (
	"encoding/json"
	"os"
)

var Conf *ConfigInfo

const (
	environment = "conf/conf.json"
)

type ConfigInfo struct {
	MysqlInfo struct {
		Host     string `json:"host"`
		Post     int    `json:"port"`
		UserName string `json:"userName"`
		Password string `json:"password"`
		DbName   string `json:"dbName"`
	} `json:"mysqlInfo"`
	SecretId    string `json:"secretId"`
	SecretKey   string `json:"secretKey"`
	Tim         int    `json:"tim"`
	CommentName string `json:"commentName"`
}

func init() {
	Conf = readConf()
}

func readConf() *ConfigInfo {
	confInfo := new(ConfigInfo)
	file, err := os.ReadFile(environment)
	if err != nil {
		return nil
	}
	err = json.Unmarshal(file, &confInfo)
	if err != nil {
		return nil
	}
	return confInfo
}
